const app = getApp()
import { getSupplierMember, postDeleteSupplierMember } from '../../../api/index'

Page({
  data: {
    members: [],
    showInvitePop: false,
    userInfo: {}
  },
  inviteMember () {
    this.setData({showInvitePop: true })
  },
  close () {
    this.setData({showInvitePop: false })
  },
  confirm () {
    this.setData({showInvitePop: false })
    this.getList()
  },
  async delMember ({ currentTarget: { dataset: { item } } }) {
    try {
      const { confirm } = await wx.$pro.showModal({ title: '删除成员', content: '确定要删除该成员吗？' })
      if (confirm) {
        wx.$pro.showLoading({ title: '删除中...', mask: true })
        await postDeleteSupplierMember({ deleteUserId: item.userId })
        wx.$pro.hideLoading()
        wx.showToast({ title: '删除成功！', icon: 'none' })
        this.getList()
      }
    } catch (err) {
      wx.$pro.hideLoading()
      wx.showToast({ title: err.message || err.ResultSet.errors, icon: 'none' })
    }
  },
  async getList () {
    try {
      const { ResultSet } = await getSupplierMember()
      this.setData({ members: ResultSet.userData.supplierMember })
    } catch (err) {
      wx.showToast({ title: err.message || err.ResultSet.errors, icon: 'none' })
    }
  },
  onLoad ({ id }) {
    // this.setData({ teamId: id })
    const { userInfo } = app.globalData
    this.setData({ userInfo })
    this.getList()
  }
})